﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using AdoNet = System.Data;
using System.Runtime.CompilerServices;

namespace DataSet4Com
{
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.AutoDispatch)]
    [ComDefaultInterface(typeof(IObjectList))]
    [Guid("7D2F5F7B-E110-415A-9446-5B6A6C72C95E")]
    public class ObjectList : IObjectList
    {
        private List<object> _list;

        public ObjectList() : this(null) { }

        public ObjectList(object[] array)
        {
            _list = new List<object>();

            if (array != null)
                _list.AddRange(array);
        }

        [ComVisible(false)]
        public List<object> InternalList
        {
            get { return _list; }
        }

        [DispId(-4)]
        public IEnumerator GetEnumerator()
        {
            return _list.GetEnumerator();
        }

        [DispId(0)]
        [IndexerName("_Default")]
        public object this[int index]
        {
            get
            {
                return _list[index];
            }
        }

        public void Add(object item)
        {
            _list.Add(item);
        }

        public void Clear()
        {
            _list.Clear();
        }

        public bool Contains(object item)
        {
            return _list.Contains(item);
        }

        public int IndexOf(object item)
        {
            return _list.IndexOf(item);
        }

        public void Remove(object item)
        {
            _list.Remove(item);
        }

        public void RemoveAt(int index)
        {
            _list.RemoveAt(index);
        }

        public int Count
        {
            get { return _list.Count; }
        }
    }

    [ComVisible(true)]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    [Guid("35EC480B-C6D0-474A-B96D-5882B0B9CE73")]
    public interface IObjectList
    {
        [DispId(-4)]
        IEnumerator GetEnumerator();

        [DispId(0)]
        [IndexerName("_Default")]
        object this[int index]
        {
            get;
        }

        void Add(object item);

        void Clear();

        bool Contains(object item);

        int IndexOf(object item);

        void Remove(object item);

        void RemoveAt(int index);

        int Count
        {
            get;
        }
    }
}
